# -*- codeing =utf-8 -*-
# @Time : 2022/9/17 上午12:31
# @Author :WXJ
# @File : 5.1.py
# @Software: PyCharm

import urllib.request
from urllib.request import urlretrieve
def getImg(str1):
    list1 = []
    while 1:
        firstSign = str1.find('img src="')
        endSign = str1.find('.jpg')
        if firstSign == -1 or endSign == -1:
            break
        list1.append("https://www.tute.edu.cn/" + str1[firstSign + 15:endSign + 4])
        str1 = str1[endSign + 4:]
    return list1
    print(list1)

url = 'https://www.tute.edu.cn/xysh/yxtzsd/1.htm'

response = urllib.request.urlopen(url)# 用于打开一个远程的url连接,并且向这个连接发出请求,获取响应结果
cc = ""
cc = response.read().decode('utf-8')
print(response.headers)

list1 = getImg(cc)
print("总共找到了{0}张图片".format(len(list1)))

urlll = 'https://www.tute.edu.cn/_mediafile/tutenew/2012/08/28/2ggtofh6of.jpg'


num = int(input("请输入要下载的图片数："))
for i in range(num):
    urlretrieve(list1[i], 'img{0}.jpg'.format(i))
print("下载成功")